<?php

namespace App\Admin\Controllers;

use App\Admin\Repositories\Video;
use Dcat\Admin\Form;
use Dcat\Admin\Grid;
use Dcat\Admin\Layout\Content;
use Dcat\Admin\Show;
use Dcat\Admin\Controllers\AdminController;

class VideoController extends AdminController
{
    public function index(Content $content)
    {
        return $content->title('视频')
            ->description('列表')
            ->body($this->grid());
    }

    public function create(Content $content)
    {
        return $content->title('视频')
            ->description('创建')
            ->body($this->form());
    }
    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        return Grid::make(new Video(), function (Grid $grid) {
            $grid->column('id')->sortable();
            $grid->column('video_name','视频名称');
            $grid->column('video_introl','视频简介');
            $grid->column('video_url','视频地址')->display(function ($value){
                 $value = config('alioss.ossServer').'/'.$value;
                return "<video src=".$value." width='150' preload='auto' controls></video>";
            });

            $grid->filter(function (Grid\Filter $filter) {
                $filter->equal('id');

            });
        });
    }

    /**
     * Make a show builder.
     *
     * @param mixed $id
     *
     * @return Show
     */
    protected function detail($id)
    {
        return Show::make($id, new Video(), function (Show $show) {
            $show->field('id');
            $show->field('video_name');
            $show->field('video_url');
        });
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        return Form::make(new Video(), function (Form $form) {
            $form->display('id');
            $form->text('video_name','视频名称');
            $form->text('video_introl','视频简介');
            $form->file('video_url','视频地址')->autoUpload()->uniqueName();
        });
    }
}
